@echo off
echo Welcome to 2FZDOS Reformation Beta 0.1.7 for x86-i386 Installer
echo Installer Script version 0.0.7 - Revised by Fariz Luqman
echo Email: 2fzweb@gmail.com
echo.
echo This product is Open source licenced, under the terms of
echo GNU's General Public Licence version 3. 
echo.
echo This product is mean to be useful but without any WARRANTY.
echo Please report any bug you see in the screen.
echo.
echo P/S: Please credit me if you take any contents of the script.

::We just use a DOS.SFX to extract the files. Before that, we need to ask whether 
::the user have formatted the drive yet or not.

::If NOT, then return errorlevel that will start FDISK application.
::If there is a hard disk already, we will just install it to the
::already existing hard drive.

::Installation is made from the drive X: (CD-ROM)
::Please avoid from using X: as your hard disk drive letter

rem REVISION 9. changes:
rem ====================

rem 0.0.1 first revision.
rem 0.0.2 added choice for installation options plus bug fixes for the trailing 
rem       slashes (/ into \), also fixes on choosing a drive (label TWO) 
rem 0.0.3 added FDISK option for user that doesn't know anything (NOOB), plus
rem       added restart option (shutdown)
rem 0.0.4 fixes on attempt to install to drive K and X, and also file 
rem       missing when we chdir to other directory so need to install from A:,
rem       also a major fixes on the choices
rem 0.0.5 Grammar revised. Fixed some bugs on installation, added reinstall
rem       option, added comments
rem 0.0.6 Describing the error rather than just echoing "ERROR ON INSTALLTION"
rem       plus added errorcode
rem 0.0.7 Current revision. plus a small fixes on the script.

rem ============================================================================

::CHDIR TO A:
A:

:CHOOSE
echo.
::THE BELOW LINE GIVES THE USER 3 CHOICES )
echo Sire, what are we going to do now?
echo.
echo 1. Setup your partitions
echo 2. Install 2FZDOS to an active partition (take about 10 MB of space)
echo 3. Exit
echo.
echo Enter your choice:
CHOICE /N /C:123

::THE NEXT THREE LINES ARE DIRECTING USER DEPENDING UPON INPUT
IF ERRORLEVEL ==3 GOTO END
IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE
GOTO END

:TWO
echo.
::the label "TWO" indicates that the user have choosed to continue the setup.
echo Define your set up hard disk: [For example: C for C:/, D for D:/ etc]
echo without selecting the drive X: and drive K:. Run "findcd" to see which 
echo CD-ROM drive letter is currently assigned.
echo.
echo Enter the drive letter:
CHOICE /N /C:CDEFGHIJLMNOPQRSTUVWYZ
echo.
IF ERRORLEVEL ==22 GOTO z
IF ERRORLEVEL ==21 GOTO y
IF ERRORLEVEL ==20 GOTO w
IF ERRORLEVEL ==19 GOTO v
IF ERRORLEVEL ==18 GOTO u
IF ERRORLEVEL ==17 GOTO t
IF ERRORLEVEL ==16 GOTO s
IF ERRORLEVEL ==15 GOTO r
IF ERRORLEVEL ==14 GOTO q
IF ERRORLEVEL ==13 GOTO p
IF ERRORLEVEL ==12 GOTO o
IF ERRORLEVEL ==11 GOTO n
IF ERRORLEVEL ==10 GOTO m
IF ERRORLEVEL ==9 GOTO l
IF ERRORLEVEL ==8 GOTO j
IF ERRORLEVEL ==7 GOTO i
IF ERRORLEVEL ==6 GOTO h
IF ERRORLEVEL ==5 GOTO g
IF ERRORLEVEL ==4 GOTO f
IF ERRORLEVEL ==3 GOTO e
IF ERRORLEVEL ==2 GOTO d
IF ERRORLEVEL ==1 GOTO c

::This is the drive assigning section.
::If the drive is not exist, then it will return to label "noexist" and
::will ask the user whether to continue choosing other drive letter of not

:c
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: C:\
echo.
set installdrive=c:
if not exist c:\nul goto noexist
goto install
goto END

:d
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: d:\
echo.
set installdrive=d:
if not exist d:\nul goto noexist
goto install
goto END

:e
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: e:\
echo.
set installdrive=e:
if not exist e:\nul goto noexist
goto install
goto END

:f
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: f:\
echo.
set installdrive=f:
if not exist f:\nul goto noexist 
goto install
goto END

:g
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: g:\
echo.
set installdrive=g:
if not exist g:\nul goto noexist 
goto install
goto END

:h
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: h:\
echo.
set installdrive=h:
if not exist h:\nul goto noexist    
goto install
goto END

:i
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: i:\
echo.
set installdrive=i:
if not exist i:\nul goto noexist 
goto install
goto END

:j
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: j:\
echo.
set installdrive=j:
if not exist j:\nul goto noexist  
goto install
goto END

:l
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: l:\
echo.
set installdrive=l:
if not exist l:\nul goto noexist 
goto install
goto END

:m
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: m:\
echo.
set installdrive=m:
if not exist m:\nul goto noexist  
goto install
goto END

:n
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: n:\
echo.
set installdrive=n:
if not exist n:\nul goto noexist    
goto install
goto END

:o
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: o:\
echo.
set installdrive=o:
if not exist o:\nul goto noexist  
goto install
goto END

:p
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: p:\
echo.
set installdrive=p:
if not exist p:\nul goto noexist  
goto install
goto END

:q
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: q:\
echo.
set installdrive=q:
if not exist q:\nul goto noexist  
goto install
goto END

:r
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: r:\
echo.
set installdrive=r:
if not exist r:\nul goto noexist  
goto install
goto END

:s
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: s:\
echo.
set installdrive=s:
if not exist s:\nul goto noexist  
goto install
goto END

:t
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: t:\
echo.
set installdrive=t:
if not exist t:\nul goto noexist 
goto install 
goto END

:u
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: u:\
echo.
set installdrive=u:
if not exist u:\nul goto noexist
goto install  
goto END
:v
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: v:\
echo.
set installdrive=v:
if not exist v:\nul goto noexist   
goto install
goto END
:w
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: w:\
echo.
set installdrive=w:
if not exist w:\nul goto noexist    
goto install
goto END
:y
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: y:\
echo.
set installdrive=y:
if not exist y:\nul goto noexist 
goto install 
goto END
:z
echo You have choosen to install 2FZDOS to the selected partition
echo Partition: z:\
echo.
set installdrive=z:
if not exist z:\nul goto noexist  
goto install
goto END

:noexist
echo.
echo Drive %installdrive% is not exist. Installation ended prematurely
echo with errorcode 1
echo.
echo Do you wish to retry?
choice
IF ERRORLEVEL ==2 GOTO END
IF ERRORLEVEL ==1 GOTO CHOOSE

goto END


:install
::Installation begins, however, another check is needed, which is whether the 
::drive is formatted or not. so, need to format them first. It is a must.
if not exist %installdrive%\KERNEL.SYS goto nofile
if exist %installdrive%\KERNEL.SYS goto havefile
goto nofile

:havefile
echo.
echo The drive seems to have the system file named KERNEL.SYS on drive 
echo %installdrive%. Assuming that you have already installed the filesystem 
echo and a boot loader to the drive. 
echo.
echo If %installdrive% is bootable, press Y. Else, press N to reinstall 2FZDOS.
choice 
IF ERRORLEVEL ==2 GOTO installstart

::User assuming that 2FZDOS is already installed, so, exiting...
IF ERRORLEVEL ==1 GOTO END


::Even though the file is already exist, user choose to continue the
::installation. so, we have to reinstall everything again, same like the 
::"nofile" label.
:installstart

:nofile
echo.
echo You need to format the drive as it is not bootable yet. 
echo Assuming that you never copied the system files to %installdrive% 
echo the drive is not bootable or need a reinstall. 
echo If so, we will format the drive to make it bootable.
echo.
echo Press any key to start the installation...
pause > nul

echo.

::Changing the directory to A: so we can copy kernel.sys and command.com
::from the drive A:
A:
format /V:2FZDOS /Q /S %installdrive%
copy X:\INSTALL\INSTALL.exe %installdrive%

if not exist %installdrive%\command.com goto error2

::Changing the directory to %installdrive% to configure INSTALLATION files.
%installdrive%
xcopy X:\INSTALL\ %installdrive%  /e /f /h

::Done extracting all files to the %installdrive%
::So now we will copy a unique autoexec.bat and config.sys depends
::on the drive letter
if %installdrive%==c: set cfg=c
if %installdrive%==d: set cfg=d
if %installdrive%==e: set cfg=e
if %installdrive%==f: set cfg=f
if %installdrive%==g: set cfg=g
if %installdrive%==h: set cfg=h
if %installdrive%==i: set cfg=i
if %installdrive%==j: set cfg=j
if %installdrive%==l: set cfg=l
if %installdrive%==m: set cfg=m
if %installdrive%==n: set cfg=n
if %installdrive%==o: set cfg=o
if %installdrive%==p: set cfg=p
if %installdrive%==q: set cfg=q
if %installdrive%==r: set cfg=r
if %installdrive%==s: set cfg=s
if %installdrive%==t: set cfg=t
if %installdrive%==u: set cfg=u
if %installdrive%==v: set cfg=v
if %installdrive%==w: set cfg=w
if %installdrive%==y: set cfg=y
if %installdrive%==z: set cfg=z

::example: (if the %installdrive% is C:)
::copy C:\TEMP\C\AUTOEXEC.BAT C:

copy X:\INSTALL\TEMP\%cfg%\AUTOEXEC.BAT %installdrive%
copy X:\INSTALL\TEMP\%cfg%\CONFIG.SYS %installdrive%

del %installdrive%\install.exe
deltree /Y /Z:seriously %installdrive%\TEMP
A:
echo.


echo 2FZDOS has been successfully installed to %installdrive%.
echo Please restart the system typing "SHUTDOWN" and press "R" to reboot.
goto END

:error2
echo.
echo Failed when trying to copy all installation files to %installdrive%.
echo.
echo The installation ended prematurely, returning errorcode 2.

goto END


::the label "ONE" here indicates that user have choosen the "TRUE" option (Y)
::So that we will start the FDISK

:ONE
echo.
ECHO You have choosen to start the FDISK. Press any key to start FDISK...
pause > nul
FDISK
echo.

::FDISK setup is complete. Now, asks for shutdown\reboot
echo Please reboot the machine if you changed a partition
echo to refresh the disk configurations.
echo.
echo Do so by typing "SHUTDOWN" and press "R" to reboot.
goto END

:END
echo.
echo Press any key to exit...
pause > nul